import 'package:flutter/material.dart';

class WFCustomHeightTextField extends StatefulWidget {
	
	final TextEditingController? ctl;
	final double? specifyHeight;
	final TextStyle textStyle;
	final String hintStr;
	
	WFCustomHeightTextField({
		this.ctl,
		this.specifyHeight,
		this.textStyle=const TextStyle(),
		this.hintStr=""
	});
	
	@override
	_WFCustomHeightTextFieldState createState() => _WFCustomHeightTextFieldState();
}

class _WFCustomHeightTextFieldState extends State<WFCustomHeightTextField> {
	
	TextEditingController? _ctl;
	double? _fontSize;
	double? _specifyHeight;
	double? _verticalPadding;
	
	@override
	void initState() {
		super.initState();
		_specifyHeight = widget.specifyHeight ?? 40;
		_fontSize = widget.textStyle.fontSize;
		_verticalPadding = (_specifyHeight==null?0:_specifyHeight! - _fontSize!) / 2;
		_ctl = widget.ctl ?? TextEditingController();
	}
	
	@override
	Widget build(BuildContext context) {
		return ConstrainedBox(
			constraints: BoxConstraints(
				maxHeight: _specifyHeight==null?0:_specifyHeight!,
			),
			child:  Scrollbar(
				child:  SingleChildScrollView(
					scrollDirection: Axis.vertical,
					reverse: true,
					child:  TextField(
						controller: _ctl,
						style: const TextStyle(
							fontSize: 14
						),
						decoration: InputDecoration(
							isDense: true,
							contentPadding: EdgeInsets.symmetric(vertical: _verticalPadding==null?0:_verticalPadding!),
							hintText: widget.hintStr
						),
					),
				),
			),
		);
	}
	
}
